package com.cuckoo.mall.thus.menuindex.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bgn.baseframe.utils.BaseStringUtil;
import com.bgn.baseframe.utils.imageloader.ImageLoader;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cuckoo.mall.R;
import com.cuckoo.mall.javabean.Product;

import java.util.List;

/**
 * Created by wanglun on 2018/3/3.
 */

public class CategoriespProductListAdapter extends BaseQuickAdapter<Product, BaseViewHolder> {

    private int itemWidth = 0;
    WhenPositionChange whenPositionChange;

    public CategoriespProductListAdapter(@Nullable List<Product> data, WhenPositionChange callBack) {
        super(R.layout.list_item_categories_list_product, data);
        whenPositionChange = callBack;
        // itemWidth = (UiUtil.getScreenWidth() - UiUtil.dip2px(10) * 4) / 2;
        //itemWidth = (UiUtil.getScreenWidth()/2);
    }

    @Override
    protected void convert(BaseViewHolder helper, Product item) {
        LinearLayout linearLayout = (LinearLayout) helper.getView(R.id.lly_root);
        ImageView imagePic = (ImageView) helper.getView(R.id.iv_good);
//        linearLayout.getLayoutParams().width = itemWidth;
//        //imagePic.getLayoutParams().width = itemWidth>linearLayout.getLayoutParams().width?linearLayout.getLayoutParams().width:itemWidth;
//        imagePic.getLayoutParams().height = itemWidth;
//        imagePic.getLayoutParams().width = itemWidth;
//        imagePic.setScaleType(ImageView.ScaleType.CENTER_CROP);

        if (helper.getAdapterPosition() >= 20) {
            whenPositionChange.changeImageViewVisibile(true);
        } else {
            whenPositionChange.changeImageViewVisibile(false);
        }
        helper.setText(R.id.tv_good_name, item.getName());
        // Glide.with(UiUtil.getContext()).load(item.getImage()).apply(new RequestOptions().override(itemWidth, itemWidth).placeholder(com.bgn.baseframe.R.mipmap.placeholder).error(com.bgn.baseframe.R.mipmap.placeholder).centerCrop()).into(imagePic);
        ImageLoader.load(item.getImage()).into(imagePic);
        helper.setText(R.id.tv_price, item.getCurrency() + " " + BaseStringUtil.getPrioceFormatString(item.getPrice()));

        if (item.getMarket_price() == 0) {
            helper.setText(R.id.tv_max_price, "");
        } else {
            //helper.setText(R.id.tv_max_price, Html.fromHtml("<strike>" + item.getCurrency() + " " + BaseStringUtil.getPrioceFormatString(item.getMarket_price()) + "</strike>"));
            helper.setText(R.id.tv_max_price, BaseStringUtil.addDeleteLineToText(item.getCurrency() + " " + BaseStringUtil.getPrioceFormatString(item.getMarket_price())));
        }

    }

    public interface WhenPositionChange {
        void changeImageViewVisibile(boolean isShow);
    }
}
